<?php


namespace App\HttpController;


use EasySwoole\Http\AbstractInterface\Controller;
use EasySwoole\Component\Di;
use App\Model\Es\EsVideo;

class Index extends Controller
{

    function index()
    {
        // $file = EASYSWOOLE_ROOT.'/vendor/easyswoole/easyswoole/src/Resource/Http/welcome.html';
        // if(!is_file($file)){
        //     $file = EASYSWOOLE_ROOT.'/src/Resource/Http/welcome.html';
        // }
        // $this->response()->write(file_get_contents($file));
        // $params = [
        //     'index' => 'video',
        //     'body' => [
        //         'query' => [
        //             'match' => [
        //                 'name' => 'wangheng',
        //             ]
        //         ],
        //     ],
        // ];
        // $client = Di::getInstance()->get('ES');
        // $result = $client->search($params);
        $params = $this->request()->getRequestParam();
        $esVideo = new EsVideo();
        $result = $esVideo->searchName($params['name']);
        return $this->writeJson(200,'OK',$result);
    }

    protected function actionNotFound(?string $action)
    {
        $this->response()->withStatus(404);
        $file = EASYSWOOLE_ROOT.'/vendor/easyswoole/easyswoole/src/Resource/Http/404.html';
        if(!is_file($file)){
            $file = EASYSWOOLE_ROOT.'/src/Resource/Http/404.html';
        }
        $this->response()->write(file_get_contents($file));
    }
}